<template>
  <div class="common-index">
    <Jyt v-if="deptId == 1"></Jyt>
    <Common v-else></Common>
    <div class="alert-info" v-if="showVisible">
      为保障账号安全，请及时更新密码；若密码遗失，请联系管理员
      <div class="control">
        <div class="btn btn-no" @click="handleDont">不再提示</div>
        <div class="btn btn-success" @click="gotoChange">去修改</div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import Common from "./common.vue";
import Cookies from "js-cookie";
import Jyt from "./jyt.vue";

export default {
  name: "Index",
  computed: {
    ...mapGetters(["deptId"]),
  },
  components: {
    Common,
    Jyt,
  },
  data() {
    return {
      showVisible: false,
    };
  },
  created() {
    this.initTice();
  },
  methods: {
    gotoChange(){
      this.showVisible = false;
      this.$router.push({
        name: 'Profile'
      })
    },
    initTice() {
      let safe = Cookies.get("WORD_SAFE");
      let dont = Cookies.get("DONT_SHOW");
      if ( safe == "0" && !dont) {
        this.showVisible = true;
        Cookies.set("WORD_SAFE",'2');
      } else {
        this.showVisible = false;
      }
    },
    handleDont(){
      Cookies.set("DONT_SHOW",'1');
      this.initTice();
    }
  },
};
</script>

<style lang="scss" scoped>
.common-index {
  background-color: #f0f2f5;
}
.alert-info {
  position: fixed;
  top: 10%;
  left: 50%;
  z-index: 99999;
  width: 570px;
  margin-left: -285px;
  background-color: #fdf6ec;
  color: #e6a23c;
  padding: 0 16px;
  height: 56px;
  line-height: 56px;
  box-sizing: border-box;
  border-radius: 4px;
  overflow: hidden;
  opacity: 1;
  display: flex;
  align-items: center;
  transition: opacity 0.2s;
  font-size: 14px;
  .control {
    position: absolute;
    top: 0;
    right: 6px;
    height: 100%;
    display: flex;

    .btn {
      margin-right: 10px;
      cursor: pointer;
    }
    .btn-success{
      color: #67c23a;
    }
    .btn-no{
      color: #909399;
    }
  }
}
</style>
